package com.o2o.app.userCenter;

import com.o2o.app.R;
import com.o2o.app.userCenter.MineFamilyActivity.ClickEvent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class MineFamilyTypeActivity extends Activity {
	private RelativeLayout rlt_01; // 加入家庭布局
	private RelativeLayout rlt_02; // 创建家庭布局

	/**
	 * 创建或者加入 1:加入 2：创建
	 */
	private String typefamily;

	/**
	 * 创建返回按钮
	 */
	private Button btn_back_02;

	/**
	 * 创建编辑按钮
	 */
	private EditText et_code_02;

	/**
	 * 创建下一步
	 */
	private Button btn_denglu_02;

	/**
	 * 加入家庭返回按钮
	 */
	private Button btn_back;

	/**
	 * 加入家庭完成按钮
	 */
	private Button btn_denglu;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.mine_add_family);

		typefamily = getIntent().getStringExtra("type");

		initViews();

		// 1是加入家庭 2是创建
		if (typefamily != null && "1".equals(typefamily)) {

			rlt_01.setVisibility(View.VISIBLE);
			rlt_02.setVisibility(View.GONE);
			initViewAdd();

		} else if (typefamily != null && "2".equals(typefamily)) {

			rlt_01.setVisibility(View.GONE);
			rlt_02.setVisibility(View.VISIBLE);
			initViewCreate();

		}
	}

	private void initViews() {
		rlt_01 = (RelativeLayout) findViewById(R.id.rlt_01);
		rlt_02 = (RelativeLayout) findViewById(R.id.rlt_02);

	}

	/**
	 * 加入id
	 */
	private void initViewAdd() {
		btn_back = (Button) findViewById(R.id.btn_back);
		btn_back.setOnClickListener(new ClickEvent());

		btn_denglu = (Button) findViewById(R.id.btn_denglu);
		btn_denglu.setOnClickListener(new ClickEvent());
	}

	/**
	 * 创建id
	 */
	private void initViewCreate() {

		btn_back_02 = (Button) findViewById(R.id.btn_back_02);
		btn_back_02.setOnClickListener(new ClickEvent());

		et_code_02 = (EditText) findViewById(R.id.et_code_02);

		btn_denglu_02 = (Button) findViewById(R.id.btn_denglu_02);
		btn_denglu_02.setOnClickListener(new ClickEvent());
	}

	/**
	 * 点击事件
	 * 
	 * @author Administrator
	 * 
	 */
	class ClickEvent implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btn_back_02: { // 创建返回按钮
				finish();
			}
				break;
			case R.id.btn_denglu_02: { // 创建下一步
				if (TextUtils.isEmpty(et_code_02.getText().toString().trim())) {
					Toast.makeText(getApplicationContext(), "请填写家庭名字",
							Toast.LENGTH_SHORT).show();
				} else {
					Intent intent = new Intent(MineFamilyTypeActivity.this,
							MineFamilySucceedActivity.class);
					intent.putExtra("name", et_code_02.getText().toString()
							.trim());
					startActivity(intent);
				}
			}
				break;
			case R.id.btn_back: { // 加入家庭返回按钮
				finish();
			}
				break;

			case R.id.btn_denglu: { // 加入家庭完成按钮
				Intent intent = new Intent(MineFamilyTypeActivity.this,
						MineFamilyListActivity.class);
				startActivity(intent);

			}
				break;
			default:
				break;
			}
		}

	}

}
